import { useState, useRef } from 'react';

export function useRefState(initialValue) {
	const ref = useRef(initialValue);
	const [value, setValue] = useState(initialValue);
	function setRefState(value) {
		setValue(value);
		ref.current = value;
	}
	return [value, ref, setRefState];
}

export type ThemeTypes = 'light' | 'dark'

export function useThemeStorage(defaultTheme: ThemeTypes): [ThemeTypes, (theme: ThemeTypes) => void] {
	const [type, setType] = useState(defaultTheme)
	function setTheme(theme: ThemeTypes) {
		localStorage.setItem('theme', theme)
		setType(theme)
	}
	return [type, setTheme]
}
